package com.biannuo.szk.community.dao.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.biannuo.szk.common.util.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * 博客表
 *
 * @TableName inv_blog
 */
@TableName(value = "inv_blog")
@Data
public class BlogDO implements Serializable {
    /**
     * id
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    /**
     * 用户id
     */
    @TableField(value = "user_id")
    private Long userId;

    /**
     * 标题
     */
    @TableField(value = "title")
    private String title;

    /**
     * 内容摘要
     */
    @TableField(value = "summary")
    private String summary;

    /**
     * 作者名称
     */
    @TableField(value = "author")
    private String author;

    /**
     * 下载积分，0表示不需要积分
     */
    @TableField(value = "download_score")
    private Integer downloadScore;

    /**
     * 内容
     */
    @TableField(value = "content")
    private String content;

    /**
     * 阅读量
     */
    @TableField(value = "view_count")
    private Integer viewCount;

    /**
     * 点赞量
     */
    @TableField(value = "agree_count")
    private Integer agreeCount;

    /**
     * 收藏量
     */
    @TableField(value = "favorite_count")
    private Integer favoriteCount;

    /**
     * 评论数量
     */
    @TableField(value = "comment_count")
    private Integer commentCount;

    /**
     * 发布状态 0草稿1已发布2关闭
     */
    @TableField(value = "publish_state")
    private Integer publishState;

    /**
     * 公开状态 1公开 0私有
     */
    @TableField(value = "public_state")
    private Integer publicState;

    /**
     * 附加资源，多个文件 逗号分割
     */
    @TableField(value = "attach_files")
    private String attachFiles;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME, timezone = "GMT+8")
    private Date createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time")
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME, timezone = "GMT+8")
    private Date updateTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        BlogDO other = (BlogDO) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
                && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
                && (this.getTitle() == null ? other.getTitle() == null : this.getTitle().equals(other.getTitle()))
                && (this.getSummary() == null ? other.getSummary() == null : this.getSummary().equals(other.getSummary()))
                && (this.getAuthor() == null ? other.getAuthor() == null : this.getAuthor().equals(other.getAuthor()))
                && (this.getDownloadScore() == null ? other.getDownloadScore() == null : this.getDownloadScore().equals(other.getDownloadScore()))
                && (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent()))
                && (this.getViewCount() == null ? other.getViewCount() == null : this.getViewCount().equals(other.getViewCount()))
                && (this.getAgreeCount() == null ? other.getAgreeCount() == null : this.getAgreeCount().equals(other.getAgreeCount()))
                && (this.getFavoriteCount() == null ? other.getFavoriteCount() == null : this.getFavoriteCount().equals(other.getFavoriteCount()))
                && (this.getCommentCount() == null ? other.getCommentCount() == null : this.getCommentCount().equals(other.getCommentCount()))
                && (this.getPublishState() == null ? other.getPublishState() == null : this.getPublishState().equals(other.getPublishState()))
                && (this.getPublicState() == null ? other.getPublicState() == null : this.getPublicState().equals(other.getPublicState()))
                && (this.getAttachFiles() == null ? other.getAttachFiles() == null : this.getAttachFiles().equals(other.getAttachFiles()))
                && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
                && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
        result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
        result = prime * result + ((getSummary() == null) ? 0 : getSummary().hashCode());
        result = prime * result + ((getAuthor() == null) ? 0 : getAuthor().hashCode());
        result = prime * result + ((getDownloadScore() == null) ? 0 : getDownloadScore().hashCode());
        result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode());
        result = prime * result + ((getViewCount() == null) ? 0 : getViewCount().hashCode());
        result = prime * result + ((getAgreeCount() == null) ? 0 : getAgreeCount().hashCode());
        result = prime * result + ((getFavoriteCount() == null) ? 0 : getFavoriteCount().hashCode());
        result = prime * result + ((getCommentCount() == null) ? 0 : getCommentCount().hashCode());
        result = prime * result + ((getPublishState() == null) ? 0 : getPublishState().hashCode());
        result = prime * result + ((getPublicState() == null) ? 0 : getPublicState().hashCode());
        result = prime * result + ((getAttachFiles() == null) ? 0 : getAttachFiles().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", userId=").append(userId);
        sb.append(", title=").append(title);
        sb.append(", summary=").append(summary);
        sb.append(", author=").append(author);
        sb.append(", downloadScore=").append(downloadScore);
        sb.append(", content=").append(content);
        sb.append(", viewCount=").append(viewCount);
        sb.append(", agreeCount=").append(agreeCount);
        sb.append(", favoriteCount=").append(favoriteCount);
        sb.append(", commentCount=").append(commentCount);
        sb.append(", publishState=").append(publishState);
        sb.append(", publicState=").append(publicState);
        sb.append(", attachFiles=").append(attachFiles);
        sb.append(", createTime=").append(createTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}
